package yixuan.entity;


import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

@Data
@AllArgsConstructor
public class JsonResult<T> implements Serializable {

    private boolean flag;

    private Integer code;

    private String message;

    private T data;


    public static JsonResult success() {
        return new JsonResult(true,200,"操作成功",null);
    }

    public static JsonResult success(Object data) {
        return new JsonResult(true,200,"操作成功",data);
    }

    public static JsonResult successMsg(String message) {
        return new JsonResult(true,200,message,null);
    }


    public static JsonResult success(String message,Object data) {
        return new JsonResult(true,200,message,data);
    }

    public static JsonResult success(CodeEnum codeEnum) {
        return new JsonResult(true,codeEnum.getCode(),codeEnum.getMessage(),null);
    }


    public static JsonResult error() {
        return new JsonResult(false,500,"操作失败",null);
    }

    public static JsonResult error(String message) {
        return new JsonResult(false,500,message,null);
    }

    public static JsonResult error(CodeEnum codeEnum) {
        return new JsonResult(false,codeEnum.getCode(),codeEnum.getMessage(),null);
    }

}
